<?php
/**
 * Created by PhpStorm.
 * User: ouryun
 * Date: 2021/6/7
 * Time: 15:57
 */

namespace app\admin\controller\api;



class WxTpl
{
    /**
     * 发送巡店预警模板消息
     * @param $openid
     * @param $admin_name
     * @param $name
     * @return array
     */
    public static function sendPatrol($openid, $admin_name, $name)
    {
        $access_token = get_access_token();
        if (!$access_token) {
            return [];
        }
        $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token;
        $params = [
            'touser' => $openid,//'oM2EB50YHTcm9NnGuiu1sCkoTino',
            'template_id' => 'q_kJQ1aEHp0ZQFGxmNChUny5Dys-GpSfW-wJNhHlprY',
            'data' => [
                'first' => [
                    'value' => "尊敬的{$admin_name}：",
                    'color' => '#173177'
                ],
                'keyword1' => [
                    'value' => "您的工作人员{$name}已离开工作岗位30分钟，请及时跟进。"
                ],
                'keyword2' => [
                    'value' => date('Y-m-d H:i:s')
                ],
                'remark' => [
                    'value' => '疫情期间，注意防护'
                ]
            ]
        ];
        $data = json_encode($params);
        $result = https_request($url, $data);
        $arr = json_decode($result, true);
        return $arr;
    }

    /**
     * 发送考勤通知
     * @param $shopName
     * @param $openid
     * @return bool
     */
    public static function sendCheck($openid, $shopName)
    {
        $access_token = get_access_token();
        if (!$access_token) {
            return false;
        }
        $url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $access_token;
        $params = [
            'touser' => $openid,//'oM2EB50YHTcm9NnGuiu1sCkoTino',
            'template_id' => '7C5lRgFf_n2_sP82GSZjiKIt7H3K0s4qY5wKa_GMWWI',
            'data' => [
                'first' => [
                    'value' => '今日门店员工迟到，门店未正常营业',
                ],
                'keyword1' => [
                    'value' => ''
                ],
                'keyword2' => [
                    'value' => $shopName
                ],
                'keyword3' => [
                    'value' => date('Y-m-d H:i:s')
                ],
                'remark' => [
                    'value' => '疫情期间，注意防护'
                ]
            ]
        ];
        $data = json_encode($params);
        $result = https_request($url, $data);
        $arr = json_decode($result, true);
        if (isset($arr['errcode']) && $arr['errcode'] == 0) {
            return true;
        }
        p($arr['errmsg']);
        return false;
    }

}